package com.cc.factory2;

import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import com.cc.config.AppConfig;
import com.cc.entity.annotation.*;

public class Test04 {
    public static void main(String[] args) {
//        ApplicationContext context = new ClassPathXmlApplicationContext("beans-annotation2.xml");
//        User user = (User) context.getBean("abc");
//        System.out.println(user);
        // 基于Java的配置
     // 基于Java的配置 @Bean显示定义
        System.out.println("===============补充：遍历IoC容器中所有的bean=======================");
        ApplicationContext context = new AnnotationConfigApplicationContext(AppConfig.class);
        String[] beanDefinitionNames = context.getBeanDefinitionNames();
        for (int i = 0; i < beanDefinitionNames.length; i++) {
            System.out.println(beanDefinitionNames[i]);
        }
        System.out.println("===============基于Java的配置 @Bean显示定义=======================");
        User user = (User) context.getBean("u1");
        System.out.println(user);
        
        Dog dog = (Dog) context.getBean("dog");
        System.out.println(dog);
        //基于Java配置 @ComponentScan自动配置
        System.out.println("===============基于Java配置 @ComponentScan自动配置=======================");
        User user2 = (User) context.getBean("abc");
        System.out.println(user2);
    }
}
